package com.warmlight.voicepacket.presenter;

import android.content.Context;

import com.warmlight.voicepacket.bean.comm.CommBean;
import com.warmlight.voicepacket.contract.PictureContract;
import com.warmlight.voicepacket.network.base.BaseResponse;
import com.warmlight.voicepacket.network.base.NetworkCallback;
import com.warmlight.voicepacket.network.base.NetworkCallbackLike;
import com.warmlight.voicepacket.network.manager.CommRequestManager;
import com.warmlight.voicepacket.utils.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

/**
 * Created by weiweijinpeng on 2018/9/10.
 */

public class PicturePresenter  implements PictureContract.Presenter {

    PictureContract.View mView;


    @Override
    public void onStart() {
    }

    public PicturePresenter(PictureContract.View view, Context context){
        mView=view;
    }

    @Override
    public void getPictureList(Map<String, Object> map) {
        CommRequestManager.getInstance().getRecommList(map, new NetworkCallback<CommBean>() {
            @Override
            public void onSuccess(BaseResponse<CommBean> result, String responseStr) {
                Log.e("推荐数据"+responseStr);
                if (result.data!=null){
                    mView.onPictureList(result.data);
                }
            }
            @Override
            public void onError(Throwable t) {
            }
        });
    }

    @Override
    public void getLikeList(Map<String, Object> map) {
        CommRequestManager.getInstance().getLike(map, new NetworkCallbackLike<CommBean>() {

            @Override
            public void onSuccess_Like(String responseStr) {
                Log.e("点击数据"+responseStr);

                JSONObject jsonObject;
                try {
                    jsonObject=new JSONObject(responseStr);
                    if (jsonObject.has("data")){
                        String data = jsonObject.getString("data");
                        mView.onLikeList(data);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable t) {
            }
        });
    }
}
